mod mover;

use mover::Mover;
use ggez::{Context, GameResult, GameError, graphics, glam::Vec2};
use rand::Rng;

pub struct State{
    movers: Vec<mover::Mover>
}

impl State{
    pub fn new() -> State {
        let mut movers: Vec<Mover> = vec![];
        let mut rng = rand::thread_rng(); 
        for _i in 0..10 {
            let location = Vec2{x: rng.gen_range(0.0..800.0 ),y: rng.gen_range(0.0..600.0)};
            let mover = mover::Mover::new(location);
            movers.push(mover);
        }
        State{ movers }
    }
}

impl ggez::event::EventHandler<GameError> for State {
    fn update(&mut self, ctx: &mut Context) -> GameResult {
        for mover in &mut self.movers {
            mover.update(ctx);
            mover.check_edges();
        }
        Ok(())
    }
    fn draw(&mut self, ctx: &mut Context) -> GameResult {
        let mut canvas = graphics::Canvas::from_frame(ctx, graphics::Color::WHITE);
        for mover in &mut self.movers {
            mover.display(ctx, &mut canvas);
        }
        canvas.finish(ctx)?;
        Ok(())
    }
}